Cause of: Incorrect context for function call

Hello.

Does someone her know the cause of the message "Incorrect context for function call" ?

In my case I'm getting this error message for line 15 of the following code:

const string fullNameSpecIndex = "\Project\Spec_Index"
 
string buildStringArrayOfAttributeType(AttrType at)[] {
    int i
 
        string result[at.size]
        for i in 0:at.size - 1 do {
                result[i] = at.strings[i]
        }
        return result
}
 
Module modSpecIndex = read(fullNameSpecIndex, false) 
AttrType typeSupplier = find(modSpecIndex, "t_Supplier")
string arrSuppliers[] = buildStringArrayOfAttributeType(typeSupplier)

 


Would be great if I could get a hint about the problem here and about the meaning of the error message.
- Michael

 


MichaelGeorg - Thu Oct 11 08:52:20 EDT 2012

Re: Cause of: Incorrect context for function call
adevicq - Thu Oct 11 09:09:55 EDT 2012

Hi,
I'm not sure that you can assign an array this way.
You should try to pass a reference of your array to your initialization function:
 

void buildStringArrayOfAttributeType(AttrType at, string &szArray[])

 


Alain

 

Re: Cause of: Incorrect context for function call
adevicq - Thu Oct 11 09:30:15 EDT 2012

adevicq - Thu Oct 11 09:09:55 EDT 2012

Hi,
I'm not sure that you can assign an array this way.
You should try to pass a reference of your array to your initialization function:
 

void buildStringArrayOfAttributeType(AttrType at, string &szArray[])

 


Alain

 

Hi again,

I tried this:
 

void x(string  &s[]) {
int i
    for (i=0; i < sizeof(s); ++i)
                s[i] = "elem " i ""
}
 
 
string w[4]
x(w)
 
for (i = 0; i < sizeof(w); ++i) {
    print "elem " i "\n"
}

 


and it works...
It seems you cannot ommit to declare the array size...
Alain

 

Re: Cause of: Incorrect context for function call
adevicq - Thu Oct 11 09:34:26 EDT 2012

adevicq - Thu Oct 11 09:30:15 EDT 2012

Hi again,

I tried this:
 

void x(string  &s[]) {
int i
    for (i=0; i < sizeof(s); ++i)
                s[i] = "elem " i ""
}
 
 
string w[4]
x(w)
 
for (i = 0; i < sizeof(w); ++i) {
    print "elem " i "\n"
}

 


and it works...
It seems you cannot ommit to declare the array size...
Alain

 

correction...
you have to indicate the array size in the function daclaration.

Re: Cause of: Incorrect context for function call
MichaelGeorg - Thu Oct 11 09:55:56 EDT 2012

adevicq - Thu Oct 11 09:34:26 EDT 2012
correction...
you have to indicate the array size in the function daclaration.

@adevicq: Thanks for your help.

Honestly I'm even more confused now. I'm sure to have tested a function like

string x()[]

successfully before I did build it into my code - but now I can't reproduce that :-(

So I need to know the size before calling the function?
As that would not be possible in my case I will then go with a Skip instead and then use other functions to get its size and convert it to an array.

Re: Cause of: Incorrect context for function call
adevicq - Fri Oct 12 08:55:42 EDT 2012

MichaelGeorg - Thu Oct 11 09:55:56 EDT 2012

@adevicq: Thanks for your help.

Honestly I'm even more confused now. I'm sure to have tested a function like

string x()[]

successfully before I did build it into my code - but now I can't reproduce that :-(

So I need to know the size before calling the function?
As that would not be possible in my case I will then go with a Skip instead and then use other functions to get its size and convert it to an array.

I would use a skip list instead...
Alain

Re: Cause of: Incorrect context for function call
llandale - Fri Oct 12 12:49:16 EDT 2012

I don't think you can use arrays like this. The array is allocated inside the function (on the stack) and de-allocated when the function terminates.

For this particular problem, I do this:
  • int NumberEnums = CountEnumeratedValues(at)
  • string EnumValues(NumberEnums)
  • PopulateEnums(at, EnumValues)

-Louie

Re: Cause of: Incorrect context for function call
Mathias Mamsch - Sat Oct 13 08:09:00 EDT 2012

We have a lot of lengthy discussion on the forum, about why returning arrays does not work and what you can do instead. Maybe it helps:

https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14301349&#14301349
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14472558#14472558
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14472624&#14472624
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14777803&#14777803

Maybe that helps, regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Cause of: Incorrect context for function call
MichaelGeorg - Tue Oct 16 09:18:32 EDT 2012

Thanks for all your broader feedback - except that I still don't know the real meaning of the error message the problem is solved for me now.

@Louie: First counting the enum entries is just the way I've gone now. (Even so I still don't really like that way.)
@Mathias: Thanks for all the additional links. My conclusion form them is you can't or at least shouldn't use arrays as return values, like Louie and Alain pointed out above. :-)

Re: Cause of: Incorrect context for function call
Mathias Mamsch - Sun Oct 21 05:46:46 EDT 2012

MichaelGeorg - Tue Oct 16 09:18:32 EDT 2012
Thanks for all your broader feedback - except that I still don't know the real meaning of the error message the problem is solved for me now.

@Louie: First counting the enum entries is just the way I've gone now. (Even so I still don't really like that way.)
@Mathias: Thanks for all the additional links. My conclusion form them is you can't or at least shouldn't use arrays as return values, like Louie and Alain pointed out above. :-)

Well the error message "invalid context for function call" tells you, that you did the function call alright, but you put it in an assignment that DXL does not know how to evaluate. The only way of assigning arrays during declaration in DXL is:
 

int ar[] = {1,2,3,4,5}

 

Now the parser finds an array declaration that matches the return value of your function, but it does not support assignment. A similar thing happens, when you try to do this:

 

 

int func() { return 3 }
 
int &ref = func()



Func returns an integer, and the ref variable has an integer type, BUT for reference variables you can only assign another variable. So it tells you used func in the wrong "context". Maybe that helps. Regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS